//
//  XJHomeController.m
//  weiboOC
//
//  Created by 徐绩 on 16/4/17.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "XJHomeController.h"
#import "XJVisitorView.h"
#import "XJStatusCell.h"
#import "XJStatusListViewModel.h"

@interface XJHomeController ()

@property (nonatomic,strong) XJStatusListViewModel *statusListViewModel;

@end

static NSString *statusID = @"statusID";
@implementation XJHomeController

-(XJStatusListViewModel *)statusListViewModel{

    if (_statusListViewModel == nil) {
        
        _statusListViewModel = [[XJStatusListViewModel alloc]init];
    }
    return _statusListViewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (!self.userLogon) {
        
        [self.visitorView setVisitorInfo:nil image:nil];
        return;
    }
    
    [self.tableView registerClass:[XJStatusCell class] forCellReuseIdentifier:statusID];
    
    [self setupUI];
    [self loadData];
}

-(void)setupUI{

    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 250;
    self.tableView.backgroundColor = [UIColor colorWithWhite:180/255.0 alpha:1];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

-(void)loadData{
    
    [self.statusListViewModel loadData:^(BOOL isSuccess) {
        
        if (isSuccess) {
            
            [self.tableView reloadData];
        }else{
            Log(@"数据请求失败");
        }
    }];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

//    Log(@"%@",self.statusListViewModel.statusArr);
    return self.statusListViewModel.statusArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    XJStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:statusID forIndexPath:indexPath];

    cell.statusViewModel = self.statusListViewModel.statusArr[indexPath.row];
    
    return cell;
}


@end
